package com.ehsy.service.impl;

import com.ehsy.modo.UserVo;
import com.ehsy.service.UserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl implements UserService {
    public static Map<Integer, UserVo> userMap = null;
    public static List<UserVo> userList = new ArrayList<>();
    static {
        userList.add(new UserVo(1, "一一", "123456"));
        userList.add(new UserVo(2, "孙二", "123456"));
        userList.add(new UserVo(3, "张三", "123456"));
        userList.add(new UserVo(4, "李四", "123456"));
        userList.add(new UserVo(5, "王五", "123456"));
        userList.add(new UserVo(6, "赵六", "123456"));
        userList.add(new UserVo(7, "钱七", "123456"));
        userList.add(new UserVo(8, "胡八", "123456"));
        userList.add(new UserVo(9, "龙九", "123456"));
        userMap = userList.stream().collect(Collectors.toMap(UserVo::getUserId, v->v));
    }

    @Override
    public UserVo getUserById(Integer id) {
        return userMap.get(id);
    }

    @Override
    public UserVo getUserByUserNameAndPassword(String userName, String userPassword) {
        return userList
                .stream()
                .filter(u-> u.getUserName().equals(userName) && u.getPassword().equals(userPassword))
                .collect(Collectors.toList())
                .get(0);
    }
}
